//
//  ST_PecGroupListCellModel.swift
//  btvideo
//
//  Created by mac on 2020/5/28.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//
import Foundation
import SwiftyJSON
import SwiftyAttributes

/**
 替换为  ST_TraitOfOperatCellModel
 */
class ST_PecGroupListCellModel : NSObject{

    var content : String!
    var duration : Int!
    var groupId : Int!
    var accid : String!
    var height : Float!
    var isCover : Int!
    var remark : String!
    var type : Int!
    var videoUrl : String!
    var width : Float!

    /**
     Supplement Properties
     */
    
    var remarkAttri = NSAttributedString()
    
    var imageDisplayHeight = 0.cgFloat
    
    var cellHeight = 0.cgFloat
    
    
    
    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON){
        
        super.init()
        
        content = json["content"].stringValue
        duration = json["duration"].intValue
        groupId = json["group_id"].intValue
        accid = json["accid"].stringValue
        
        height = json["height"].floatValue
        isCover = json["is_cover"].intValue
        remark = json["remark"].stringValue
        type = json["type"].intValue
        videoUrl = json["video_url"].stringValue
        width = json["width"].floatValue
        
        
        let p = NSMutableParagraphStyle()
        
        p.lineSpacing = 5
        
        var attriHeight = 0.cgFloat
        
        if remark.count > 0{

            remarkAttri = remark.withAttributes([Attribute.font(Font.systemFont(ofSize: 14, weight: UIFont.Weight.medium)),.textColor(Color.init(hex: 0x333333)!),.paragraphStyle(p)])
            
            attriHeight = remarkAttri.height(withConstrainedWidth: ST_PecGroupListCell.width - 5)
            
            if attriHeight > 40 {
                attriHeight = 36
            }
        }
        
        
    
        var w = json["width"].floatValue
        
        if self.width < 1{
            w = 1
        }
        
        var h = ST_PecGroupListCell.width/w.cgFloat*self.height.cgFloat
        
        if h > ST_PecGroupListCell.width*2{
            h = ST_PecGroupListCell.width*2
        }
        
        self.imageDisplayHeight = h
        
        self.cellHeight = self.imageDisplayHeight
        if attriHeight > 0{
            self.cellHeight += attriHeight + 8
        }
    }
}
